<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">名称：</label>
        <div class="layui-input-block">
            <input type="text" name="remark" id="remark" placeholder="请输入备注" value=""
                   lay-verify="required" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">导出数据层级</label>
        <div class="layui-input-inline">
            <select name="status" id="status" lay-verify="required" lay-search="">
                <option value="1" selected>主表</option>
                <option value="2">子表</option>
                <option value="3">主子表</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
            <select name="type" id="type" lay-verify="required" lay-search="">
                <option value="QUOTATION" selected>报价单</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <input type="text" name="id" id="id" style="display: none"
               class="layui-input">
        <label class="layui-form-label ">客人:</label>
        <div class="layui-input-inline">
            <select  name="customerId" id="customerId" lay-search="">
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label ">工厂</label>
        <div class="layui-input-inline">
            <select name="supplierId" id="supplierId" lay-search="">
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="/static/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/static/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="/static/lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>
<script src="/static/js/common.js"></script>
<script>
    let id = $.common.getUrlParam("id");
    let supplierId = $.common.getUrlParam("supplierId");
    let customerId = $.common.getUrlParam("customerId");
    let status = $.common.getUrlParam("status");
    let user = $.common.getUserInfo();
    $("#status").val(status);
    if (0 != user.powerDataType) {
        $('#totalPrice').attr("disabled", true);
    }
    if (2 == user.powerDataType) {
        $('#showPowerDisplay').css("display", "none");
    }
    layui.use(['form', 'upload', 'element', 'layer'], function () {
        var form = layui.form,
            upload = layui.upload,
            layer = layui.layer,
            table = layui.table,
            util = layui.util;
        //初始化下拉框 客人
        let callback = {
            onSuccess: function (result) {
                if (result.code == '0') {
                    $('#customerId').append(new Option('请选择', '', true));// 下拉菜单里添加元素
                    $.each(result.data, function (index, item) {
                        let option = new Option(item.customerName, item.id);
                        if (customerId) {
                            if (item.id == customerId) {
                                option.selected = true;
                            }
                        }
                        $('#customerId').append(option);// 下拉菜单里添加元素
                    });
                } else {
                    $.common.showErrorMessage(result.message)
                    return false;
                }
            }
        };
        $.xAjax('/customer/select', 'POST', JSON.stringify({}), callback);


        //工厂
        let callback1 = {
            onSuccess: function (result) {
                if (result.code == '0') {
                    $('#supplierId').append(new Option('请选择', '', true));// 下拉菜单里添加元素
                    $.each(result.data, function (index, item) {
                        let option = new Option(item.supplierName, item.id);
                        if (supplierId) {
                            if (item.id == supplierId) {
                                option.selected = true;
                            }
                        }
                        $('#supplierId').append(option);// 下拉菜单里添加元素
                    });
                } else {
                    $.common.showErrorMessage(result.message)
                    return false;
                }
            }
        };
        $.xAjax('/supplier/select', 'POST', JSON.stringify({}), callback1);

        //初始化下拉框
        form.render("select");
        //监听提交
        form.on('submit(saveBtn)', function (data) {

            let url = "/exportModelConfig/saveOrUpdate";
            let callback = {
                onSuccess: function (result) {
                    if (result.code == '0') {
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.location.reload();
                        parent.layer.close(iframeIndex);
                    } else {
                        $.common.showErrorMessage(result.message)
                        return false;
                    }
                }
            };
            $.xAjax(url, 'POST', JSON.stringify(data.field), callback);
            return false;
        });

    });
</script>
</body>
</html>